package library.gui.dialog;

import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.stage.Stage;
import library.gui.SystemApplication;

public class NotiDialog extends Dialog<ButtonType> {
	
	public NotiDialog(String title, String head, String body) {
		this.setTitle(title);
		((Stage)this.getDialogPane().getScene().getWindow())
			.getIcons().add(SystemApplication.ICON);
		this.setHeaderText(head);
		this.setContentText(body);
		this.getDialogPane().setPrefWidth(360);
		listen(ButtonType.OK, ()->{});
	}
	
	public NotiDialog(String head, String body) {
		this("提示", head, body);
	}
	
//	public NotiDialog listenOk() {
//		return listen(ButtonType.OK, ()->{});
//	}
	
	public NotiDialog listen(ButtonType type, Runnable call) {
		this.getDialogPane().getButtonTypes().add(type);
		((Button)this.getDialogPane().lookupButton(type)).setOnAction((e)->{
			if(call != null) call.run();
		});
		return this;
	}
	
}
